package cc.iits.demo.crane.service.support.mybatis;

import cc.iits.demo.crane.commom.IdWorker;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;

/**
 * id生成器
 */
public class CustomIdGenerator implements IdentifierGenerator {

    IdWorker idWorker = null;

    public CustomIdGenerator(long workerId, long datacenterId) {
        idWorker = new IdWorker(workerId, datacenterId);
    }

    @Override
    public Number nextId(Object entity) {
        //可以将当前传入的class全类名来作为bizKey,或者提取参数来生成bizKey进行分布式Id调用生成.
        String bizKey = entity.getClass().getName();
        return idWorker.nextId();
    }
}
